/*    */ package xin.petstore.framework.cas;
/*    */ 
/*    */ import java.io.IOException;
/*    */ import javax.servlet.Filter;
/*    */ import javax.servlet.FilterChain;
/*    */ import javax.servlet.FilterConfig;
/*    */ import javax.servlet.ServletException;
/*    */
/*    */ import javax.servlet.ServletRequest;
/*    */ import javax.servlet.ServletResponse;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import org.apache.commons.lang3.StringUtils;
/*    */ import org.apache.shiro.SecurityUtils;
/*    */ import org.apache.shiro.authc.AuthenticationException;
/*    */ import org.apache.shiro.cas.CasToken;
/*    */ import org.apache.shiro.subject.Subject;
/*    */ import org.slf4j.Logger;
/*    */ import org.slf4j.LoggerFactory;
/*    */ 
/*    */ public class ProxyFilter
/*    */   implements Filter
/*    */ {
/* 23 */   private static Logger logger = LoggerFactory.getLogger(ProxyFilter.class);
/*    */   private static final String TICKET_PARAMETER = "ticket";
/* 28 */   private String ticketParameter = "ticket";
/*    */ 
/*    */   public String getTicketParameter() {
/* 31 */     return this.ticketParameter;
/*    */   }
/*    */ 
/*    */   public void setTicketParameter(String ticketParameter) {
/* 35 */     this.ticketParameter = ticketParameter;
/*    */   }
/*    */ 
/*    */   public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
/*    */     throws IOException, ServletException
/*    */   {
/* 41 */     HttpServletRequest httpRequest = (HttpServletRequest)request;
/* 42 */     String ticket = httpRequest.getParameter(getTicketParameter());
/* 43 */     if (StringUtils.isNotEmpty(ticket))
/*    */       try {
/* 45 */         Subject subject = SecurityUtils.getSubject();
/* 46 */         subject.login(new CasToken(ticket));
/* 47 */         response.getOutputStream().print("s");
/*    */       } catch (AuthenticationException e) {
/* 49 */         response.getOutputStream().print("f");
/* 50 */         logger.error("login error\n", e);
/*    */       }
/*    */     else
/* 53 */       chain.doFilter(request, response);
/*    */   }
/*    */ 
/*    */   public void init(FilterConfig arg0)
/*    */     throws ServletException
/*    */   {
/*    */   }
/*    */ 
/*    */   public void destroy()
/*    */   {
/*    */   }
/*    */ }

/* Location:           C:\java代码反编译器\core-1.1.4.jar
 * Qualified Name:     com.eloancn.framework.cas.ProxyFilter
 * JD-Core Version:    0.6.0
 */